Branching in Git

The Master Branch

When you initialize a git project, all work by default is done on the master branch. When you make your first commit, the master branch is automatically created.

Note: You can have the master branch be main using git branch -M main after the first commit.

You can create new branches from the master branch when you develop new features in your project or when you do testing. You can also see which branch you're on by using the git branch command.

# Here's an example of the Phaktionz-CLI branches 
$ git branch 
* beta
# As can be seen, the master branch is switched to main 
# and the current branch being worked on is the beta branch. 

Creating a New Branch

In Git, the git branch branch_name command is used to create a new branch called branch_name. Branches should be named something that describes the purpose of the branch.

For example: The beta branch represents the beta channel of Phaktionz-CLI.

Also a branch name cannot contain white spaces: some_name or some-name are valid, however some name is invalid.

Deleting a Branch

In Git, you can delete a branch by using git branch -d branch_name, and then the branch named, branch_name will be removed.

Note: Usually it's a good idea to merge the branch with the master branch before deleting.

Merging a Branch

In Git, if you would like to merge a branch with another, use the git merge command. When you use the command git merge branch_name, it will merge the branch, branch_name to the branch you're currently on.

This is useful when your new feature works, so you can merge all the changes in that branch to your master branch.